from perceptron import perceptron
from votedron import votedron
from util import *
from random import shuffle
from os import getcwd

"""
MAIN

runs the regular perceptron and the voted perceptron = the votedron.
"""
    
def main(arg=None):
    
    if arg == None: 
        
        train_file = getcwd()[:getcwd().rindex('/')]+'/SPECT.train'
        test_file =  getcwd()[:getcwd().rindex('/')]+'/SPECT.test'
        epochs = 2
        
    else:
        
        train_file = arg[0]
        test_file  = arg[1]
        epochs = arg[2]
        
    train_instances = read_plain(train_file)
    print "Read", train_file[train_file.rindex('/')+1:], 'with', len(train_instances), 'instances'
    
    shuffle(train_instances)
    
    p = perceptron([0 for i in range(len(train_instances[0]))])
    v = votedron([0 for i in range(len(train_instances[0]))], kernel(3))

    test_instances = read_plain(test_file)
    print "Read",test_file[test_file.rindex('/')+1:],"with",len(test_instances), 'instances'

    print "Traing for", epochs,"epochs"
    
    p.train(train_instances, epochs)
    v.train(train_instances, epochs)
    
    p_miss = p.test(test_instances)
    print "TestP:",p_miss,"misses from",len(test_instances),"(",int(100.0*float(p_miss)/len(test_instances)),"%)"

    v_miss = v.test(test_instances)
    print "TestV:",v_miss,"misses from",len(test_instances),"(",int(100.0*float(v_miss)/len(test_instances)),"%)"

if __name__ == "__main__":

    main()
